import { Table } from 'antd';
import React, { useEffect, useState } from 'react'
import { orderQuery } from '../service/orderService';
const columns = [
    {
        title: '订单编号',
        dataIndex: 'orderid',
        key: 'orderid',
        align: 'center',
    },
    {
        title: '甲方名称',
        dataIndex: 'partaname',
        key: 'partaname',
        align: 'center',
    },
    {
        title: '产品名称',
        dataIndex: 'productname',
        key: 'productname',
        align: 'center',
    },
    {
        title: '表面处理(颜色)',
        dataIndex: 'productcolor',
        key: 'productcolor',
        align: 'center',
    },
    {
        title: '出线方向',
        dataIndex: 'productdirection',
        key: 'productdirection',
        align: 'center',
    },
    {
        title: '光源',
        dataIndex: 'productlight',
        key: 'productlight',
        align: 'center',
    },
    {
        title: '规格(mm)',
        dataIndex: 'productsize',
        key: 'productsize',
        align: 'center',
    },
    {
        title: '数量(支)',
        dataIndex: 'productnum',
        key: 'productnum',
        align: 'center',
    },
    {
        title: '单价(元/米)',
        dataIndex: 'productprice',
        key: 'productprice',
        align: 'center',
    },
    {
        title: '金额',
        dataIndex: "totalprice",
        key: 'totalprice',
        align: 'center',
    },
]
export default function Orderlist() {
    let [orderlist, setOrderlist] = useState([])
    const fn = async () => {
        let { data } = await orderQuery()
        setOrderlist(data.list.map(item => {
            item.orderid = (<a href={'#/menu/order/product/' + item.orderid} >{item.orderid}</a >);
            item.totalprice = item.productnum * item.productprice;
            item.partaname = item.partaid?.partaname;
            return item
        }))
    }
    useEffect(() => {
        fn()
    }, [])
    return (
        <div style={{ textAlign: 'start' }}>
            <Table
                rowKey={(record) => record._id}
                columns={columns}
                dataSource={orderlist}
                pagination={{ pageSize: 9 }}
                bordered
            />
        </div >
    )
}
